#!/usr/bin/env ruby
require 'optparse'
require 'pathname'

@languages = %w[python ruby node]
@help = <<~HELP
  各种语言的切换源的场景，调用命令如：

      switch-mirror python
      switch-mirror ruby

  支持的语言列表：

  #{ @languages.map{|lang| "  - #{lang}"}.join("\n") }
HELP

ARGV.push('--help') if ARGV.empty?
begin
  OptionParser.new do |opts|
    opts.banner = @help
  end.order!
rescue OptionParser::ParseError => ex
  STDERR.puts ex.message
  exit 1
end

lang = ARGV.shift
if @languages.include?(lang) 
  exec File.join(__dir__, lang), *ARGV
else
  STDERR.puts "Unsupported language: #{lang}"
  exit 2
end
